#include "../head.h"

int main()
{
    //判断管道文件是否存在 存在返回0 否则返回-1
    if (access("/home/jinyu/fifo1",F_OK) == -1)
    {
        int ret = mkfifo("/home/jinyu/fifo1",0777);
        printf("%d\n",ret);
    }
    else
    {
        printf("管道已存在\n");
    }
    int fd = open("/home/jinyu/fifo1",O_RDWR);

    //读取文件
    while (1)
    {
        char buf[32] = {0};
        read(fd,buf,sizeof(buf));
        printf("buf = %s\n",buf);
        printf("读取成功\n");
        if (strcmp(buf,"#") == 0)
        {
            printf("退出程序\n");
            exit(0);
        }
        sleep(2);
    }
    
    close(fd);

    return 0;
}